package com.societyGames.flashForms
{
	import com.societyGames.system.EventObject;
	
	import flash.text.TextField;

	public class DynamicTextField extends TextField implements IChangeSize
	{
		private var _sizeChangedEventObject:EventObject;
		private var _lastWidth:Number;
		private var _lastHeight:Number;
		
		public function DynamicTextField()
		{
			this._sizeChangedEventObject = new EventObject(this, "SIZE_CHANGED");	
		}
		
		public function get sizeChangedEventObject():EventObject
		{
			return this._sizeChangedEventObject;
		}
		
		public override function set text(value:String):void
		{
			super.text = value;
			reactToPossibleSizeChange();
		}
		
		public override function set htmlText(value:String):void
		{
			super.htmlText = value;
			reactToPossibleSizeChange();
		}
		
		private function reactToPossibleSizeChange():void
		{
			if (this._lastWidth != this.width || this._lastHeight != this.height)
			{				
				this._lastWidth = this.width;
				this._lastHeight = this.height;
				this.sizeChangedEventObject.dispatchEvent();
			}
		}
	}
}